# _*_ coding : utf-8 _*_
# @Time : 2024-05-29 12:35
# @Author : haowen
# @File : 7.视频检测
# @Project : face identifying
import cv2 as cv
# 检测函数
def face_detect_method(img):
    gray = cv.cvtColor(img,cv.COLOR_BGR2RGB)
    face_detect = cv.CascadeClassifier("./haarcascade_frontalface_default.xml")
    face = face_detect.detectMultiScale(gray)
    for x,y,w,h in face:
        cv.rectangle(img,(x,y),(x+w,y+h),color=(0,0,255),thickness=2)

    cv.imshow("result",img)

# 读取摄像头
# cap = cv.VideoCapture(0)
cap = cv.VideoCapture("video/IMG_1421.MP4")

while True:
    flag,frame = cap.read()
    if not flag:
        break
    face_detect_method(frame)
    if ord('q') == cv.waitKey(1):
        break

cv.destroyAllWindows()
cap.release()